<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#1AA094" unique-opened  router>
            <template v-for="item in items">
                <!-- <template v-if="item.subs">
                    <el-submenu :index="'menu_'+item.lanmuId" :key="'menu_'+item.lanmuId">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs"  :index="'menu_'+subItem.lanmuId"  :route="{ path: '/'+subItem.index,query:{lanmuId:subItem.lanmuId,title:subItem.title}}">
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>v-else -->
                <template >
                    <el-menu-item   :index="'menu_'+item.lanmuId"   :route="{ path: '/'+item.index,query:{lanmuId:item.lanmuId,title:item.title}}">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from '../common/bus';
    export default {
        data() {
            return {
                collapse: false,
                items:[{
                            "lanmuId": 31,
                            "icon": "fa fa-home",
                            "index": "dashboard",
                            "title": "系统首页"
                        }, {
                            "lanmuId": 38,
                            "icon": " fa fa-plus-square-o",
                            "index": "goodsEdit",
                            "title": "添加商品"
                        },{
                             "lanmuId": 38,
                            "icon": "fa fa-shopping-basket",
                            "index": "goodslist",
                            "title": "商品列表"
                        },
                        {
                            "lanmuId": 45,
                            "icon": "fa fa-file-text-o",
                            "index": "order",
                            "title": "订单管理"
                        },
                        {
                            "lanmuId": 45,
                            "icon": "fa fa-user-circle-o",
                            "index": "account",
                            "title": "账号管理"
                        },
                    ],
            }
        },
        methods:{
          getMenu(){
            //   this.$axios.get('/getMenu',
            //       {
            //           params:{page: 1}
            //       }
            //   ).then((res) => {
            //       this.items = res.data.data;
            //   })
            // this.items=

          }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        },
        created(){
            this.getMenu();
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
                console.log(msg)
            });
            // bus.$on('menus', menus => {
            //     this.items = menus;
            // })
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 150px;
    }
    .sidebar > ul {
        height:100%;
    }
    
    .sidebar .el-menu .el-menu-item .fa, .el-submenu__title .fa {
        width: 24px;
        text-align: center;
        font-size: 18px;
        margin-right: 5px;
    }
    .sidebar .el-menu .el-menu-item .fa.fa-shopping-basket{
        font-size: 16px;
    }
    .sidebar .el-menu .el-menu-item .fa.fa-plus-square-o{font-size: 20px;}
</style>
